package com.sicaolong.partterndesign._02strategy._01;

import java.util.Arrays;

public class Sorter {
    public static void main(String[] args) {
        Cat[] c = {new Cat("毛毛", 4), new Cat("阿奇", 3), new Cat("小丽", 6)};
        sort(c);
        System.out.println(Arrays.toString(c));


        Dog[] dogs = {new Dog("毛毛-dog", 4), new Dog("阿奇-dog", 3), new Dog("小丽-dog", 6)};
        sort2(dogs);
        System.out.println(Arrays.toString(dogs));
    }

    private static void sort(MyComparable[] arrays) {
        for (int i = 0; i < arrays.length; i++) {
            MyComparable min = arrays[i];
            int temp = i;
            for (int j = arrays.length - 1; j > i; j--) {
                if (min.compareTo(arrays[j]) > 0) {
                    min = arrays[j];
                    temp = j;
                }
            }
            arrays[temp] = arrays[i];
            arrays[i] = min;
        }
    }

    private static void sort2(MyComparable2[] arrays) {
        for (int i = 0; i < arrays.length; i++) {
            MyComparable2 min = arrays[i];
            int temp = i;
            for (int j = arrays.length - 1; j > i; j--) {
                if (min.compareTo(arrays[j]) > 0) {
                    min = arrays[j];
                    temp = j;
                }
            }
            arrays[temp] = arrays[i];
            arrays[i] = min;
        }
    }


}
